package com.wenx;

import java.util.List;

public class PreorderTraversal extends AbstractTreeSorts {

    @Override
    public List<Integer> treeTraversal() {
        super.setData();
        treeTraversal(root);
        return result;
    }

    private void treeTraversal(TreeNode treeNode) {
        result.add(treeNode.getData());

        if(treeNode.getLeft() != null) {
            treeTraversal(treeNode.getLeft());
        }
        if(treeNode.getRight() != null) {
            treeTraversal(treeNode.getRight());
        }
    }

}
